<?php defined('SYSPATH') OR die('No direct access allowed.');

class Produksi_Controller extends Controller {

	public function __construct()
	{
		parent::__construct();
		$this->produksi_model = new Produksi_Model;
		$this->menu_model = new Menu_Model;
		$this->lokasi_model = new Lokasi_Model;
	}
	
	public function index()
	{
		if(!parent::_authenticate()) {
			return;
		}
		parent::_loadContent("Daftar Produksi", 'produksi_content');
		$this->view->content->produksi_model = $this->produksi_model;
		$this->view->content->menu_model = $this->menu_model;
		$this->view->content->lokasi_model = $this->lokasi_model;
		$this->view->render(TRUE);
	}

    public function add_produksi() {
        $this->today = date("Y-m-d");
        $this->produksi_model->insert_produksi(
                $this->input->post('lokasi'),   //ID_Lokasi
                $this->input->post('menu'),     //ID_menu
                $this->today,                   //current date
                $this->input->post('made'),     //jumlah produksi
                $this->input->post('sold'),     //jumlah terjual
                $this->input->post('sold')*($this->menu_model->get_menu($this->input->post("menu"))->harga_jual),//pendapatan                                
                0 //pengeluaran				
            );
		$this->menu_model->produce_menu($this->input->post('menu'));
        url::redirect('produksi');
    }
}
